<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8" />
  <title>example2_4.html</title>
  <script type="text/javascript">
    function calc()
    {
      //获取id为input1输入域的值，并赋给变量dividend
      var dividend = document.forms[0].dividend.value;
      //获取id为input2输入域的值，并赋给变量divisor
      var divisor = document.getElementsByTagName("input")[1].value;
      var result = 0;
      result = dividend / divisor;
      //弹出对话框，显示计算结果
      alert("运行结果：" + dividend + " / " + divisor + " = " +result );
    }
  </script>
</head>

<body>
<!-- 在form标签中使用onSubmit事件处理程序调用calc()函数-->
<form id="calc" name="calcForm" action="#" method="post" onSubmit="calc()">
  被除数：
  <input type="text" name="dividend" id="input1"> <br/>
  <br/>
  除&nbsp;数：
  <input type="text" name="divisor" id="input2"> <br/> <br/>
  <input type="submit" id="btn" value="计算">
</form>
</body>
</html>
